package org.lql.algo.codecrush.week007;

/**
 * @author: liangqinglong
 * @date: 2025-08-18 08:01
 * @description:
 **/
public class SearchInsert {

	public int searchInsert(int[] nums, int target) {
		int left = 0;
		int right = nums.length ;
		while (left < right) {
			int mid = (left + right) >> 1;
			if (nums[mid] >= target) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		return right;
	}

	public static void main(String[] args) {
		SearchInsert searchInsert = new SearchInsert();
		int[] nums = {1, 3, 5, 6};
		System.out.println(searchInsert.searchInsert(nums, 5));
		System.out.println(searchInsert.searchInsert(nums, 2));
	}
}
